<?php
/*!
 * Theme Name:One Nav
 * Theme URI:https://www.iotheme.cn/
 * Author:iowen
 * Author URI:https://www.iowen.cn/
 */
if ( ! defined( 'ABSPATH' ) ) { exit; } ?>
<?php
if( !empty($_POST['user_reg']) ) {
    $error = $user_error = $email_error = $pass_error = $pass_error2 = '';
    $sanitized_user_login = sanitize_user( $_POST['user_login'] );
    $user_email = apply_filters( 'user_registration_email', $_POST['user_email'] );

      // 检查名称
    if ( $sanitized_user_login == '' ) {
        $user_error .= (__( '请输入用户名！', 'i_theme' ));
    } elseif ( strlen($sanitized_user_login) < 5 ) {
        $user_error .= (__( '用户名长度至少5位!', 'i_theme' ));
        $sanitized_user_login = '';
    } elseif ( ! validate_username( $sanitized_user_login ) ) {
        $user_error .= (__( '此用户名包含无效字符，请输入有效的用户名！', 'i_theme' ));
        $sanitized_user_login = '';
    } elseif ( username_exists( $sanitized_user_login ) ) {
        $user_error .= (__( '该用户名已被注册，请再选择一个！', 'i_theme' ));
    }

      // 检查邮件
    if ( $user_email == '' ) {
        $email_error .= (__( '请填写电子邮件地址！', 'i_theme' ));
    } elseif ( ! is_email( $user_email ) ) {
        $email_error .= (__( '电子邮件地址不正确！', 'i_theme' ));
        $user_email = '';
    } elseif ( email_exists( $user_email ) ) {
        $email_error .= (__( '该电子邮件地址已经被注册，请换一个！', 'i_theme' ));
    }

    // 检查密码
    if(strlen($_POST['user_pass']) < 6)
        $pass_error .= (__( '密码长度至少6位!', 'i_theme' ));
    elseif($_POST['user_pass'] != $_POST['user_pass2'])
        $pass_error2 .= (__( '密码不一致!', 'i_theme' ));
 
    if($user_error == '' && $email_error == '' && $pass_error == '' && $pass_error2 == '') {

        $user_id = wp_create_user( $sanitized_user_login, $_POST['user_pass'], $user_email );
        if ( ! $user_id ) {
            $error .= sprintf( '无法完成您的注册请求... 请联系<a href="mailto:%s">管理员</a>！', get_option( 'admin_email' ) );
        }
        else if (!is_user_logged_in()) {
            $user = get_user_by('login',$sanitized_user_login);
            $user_id = $user->ID;

              // 自动登录
            wp_set_current_user( $user_id, $user->user_login );
            wp_set_auth_cookie( $user_id );
            do_action( 'wp_login', $user->user_login );
        }
    }
}
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title><?php _e( '注册', 'i_theme' ); ?> - <?php bloginfo('name') ?></title>
<link rel="shortcut icon" href="<?php echo io_get_option('favicon')['url'] ?>">
<link rel="apple-touch-icon" href="<?php echo io_get_option('apple_icon')['url'] ?>">
<meta name='robots' content='noindex,nofollow' />
<link rel="stylesheet" href="<?php echo get_theme_file_uri('/css/iconfont.css') ?>?ver=<?php echo VERSION ?>" type="text/css">
<link rel="stylesheet" href="<?php echo get_theme_file_uri('/css/bootstrap.min.css') ?>?ver=<?php echo VERSION ?>" type="text/css"/>
<script type="text/javascript" src="<?php echo get_theme_file_uri('/js/jquery.min.js') ?>?ver=<?php echo VERSION ?>"></script>
<?php do_action('login_head', 'resetpass'); ?>
<?php $login_color = io_get_option('login_color'); ?>
<style type="text/css">
    body {
        background: linear-gradient(45deg, <?php echo $login_color['color-l'] ?>, <?php echo $login_color['color-r'] ?>);
        height: 100vh;
    }
    .login-page {
        position: relative;
    }
    .login-page .container {
        min-height: 100vh;
        z-index: 999;
        padding: 20px;
        position: relative;
    }
    .login-page .form-holder {
        width: 100%;
        border-radius: 8px;
        overflow: hidden;
        margin-bottom: 50px;
    }
    .has-shadow {
        -webkit-box-shadow: 0 20px 0 -10px rgba(255, 255, 255, 0.3), 0 40px 0 -20px rgba(255, 255, 255, 0.1);
        box-shadow: 0 20px 0 -10px rgba(255, 255, 255, 0.3), 0 40px 0 -20px rgba(255, 255, 255, 0.1);
    } 
    .login-page .form-holder .info, .login-page .form-holder .form {
        min-height: 450px;
        height: 100%;
    }
    .login-page .form-holder .info {
        background: rgba(241, 64, 75, .9);
        color: #fff;
        background-size: cover;
        background-position: 50% 50%;
        background-repeat: no-repeat;
    }
    .login-page .form-holder .form .content {
        width: 100%;
    }
    .login-page .form-holder .form form {
        width: 100%; 
    } 
    button, input {
        outline: none !important;
    }
    input.input-material {
        width: 100%;
        border: none;
        border-bottom: 1px solid #eee;
        padding: 10px 0;
        transition: .3s;
        letter-spacing: .25rem;
    }
    input.input-material.is-invalid {
      border-color: #f1404b !important;
    }

    input.input-material:focus {
      border-color: #f1404b;
    }
    .btn-danger {
      color: color-yiq(#f1404b);
      background-color: #f1404b;
      border-color: #f1404b;
      box-shadow: 0 6px 20px -5px #f1404b;
    }
    .btn-danger:hover {
      color: color-yiq(#222);
      background-color: #222;
      border-color: #222;
      box-shadow: none;
    }
    .btn-danger:focus, .btn-danger.focus {
      -webkit-box-shadow: 0 0 0 0.2rem rgba(241, 64, 75, 0.5);
      box-shadow: 0 0 0 0.2rem rgba(241, 64, 75, 0.5);
    }
    .btn-danger.disabled, .btn-danger:disabled {
      color: color-yiq(#f1404b);
      background-color: #f1404b;
      border-color: #f1404b;
    }
    .btn-danger:not(:disabled):not(.disabled):active, .btn-danger:not(:disabled):not(.disabled).active,
    .show > .btn-danger.dropdown-toggle {
      color: color-yiq(#222);
      background-color: #222;
      border-color: #222;
    }
    .btn-danger:not(:disabled):not(.disabled):active:focus, .btn-danger:not(:disabled):not(.disabled).active:focus,
    .show > .btn-danger.dropdown-toggle:focus {
      -webkit-box-shadow: 0 0 0 0.2rem rgba(20, 20, 20, 0.5);
      box-shadow: 0 0 0 0.2rem rgba(20, 20, 20, 0.5);
    }
    .btn-outline-danger {
      color: #f1404b;
      border-color: #f1404b;
    }

    .btn-outline-danger:hover {
      color: #fff;
      background-color: #f1404b;
      border-color: #f1404b;
          box-shadow: 0 6px 20px -5px #f1404b;
    }

    .btn-outline-danger:focus, .btn-outline-danger.focus {
      box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.5);
    }

    .btn-outline-danger.disabled, .btn-outline-danger:disabled {
      color: #f1404b;
      background-color: transparent;
    }

    .btn-outline-danger:not(:disabled):not(.disabled):active, .btn-outline-danger:not(:disabled):not(.disabled).active,
    .show > .btn-outline-danger.dropdown-toggle {
      color: #fff;
      background-color: #f1404b;
      border-color: #f1404b;
    }

    .btn-outline-danger:not(:disabled):not(.disabled):active:focus, .btn-outline-danger:not(:disabled):not(.disabled).active:focus,
    .show > .btn-outline-danger.dropdown-toggle:focus {
      box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.5);
    }

    .iconfont {
        display: inline-block;
        font-size: inherit;
        font-variant: normal;
        text-rendering: auto;
        line-height: 1;
    }
    .icon-spin{
        -webkit-animation:icon-spin 2s infinite linear;
        animation:icon-spin 2s infinite linear;
    }
    @-webkit-keyframes icon-spin{
        0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}
        100%{-webkit-transform:rotate(359deg);transform:rotate(359deg)}
    }
    @keyframes icon-spin{
        0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}
        100%{-webkit-transform:rotate(359deg);transform:rotate(359deg)}
    }
    .footer-copyright{
        position: absolute;
        bottom: 0;
        width: 100%;
    }
    @media (max-width:767.98px){
    input.input-material {
        padding: 5px 0;
    }
    }
    .openlogin-box{display:block;margin-bottom:10px !important;}
    .openlogin-box a{width:35px;height:35px;line-height:35px;text-align:center;display:inline-block;margin-right:10px;color:#fff;border-radius:3px;text-decoration: none;background:#19b6f5}
    .openlogin-box a.openlogin-weibo-a{background:#ff545a}
    .openlogin-box a.openlogin-wechat-a{background:#2fac1a}
</style>
</head>
<body <?php body_class(theme_mode()); ?> >
    
    <div class="page login-page">
        <div class="container d-flex align-items-center">
            <div class="form-holder has-shadow">
                <div class="row no-gutters">
                    <!-- Logo & Information Panel-->
                    <div class="col-md-6 col-lg-7 d-none d-md-block">
                        <div class="info d-flex p-5" style="background-image: url(<?php echo io_get_option('login_ico')['url'] ?>);">
                            <div class="content">
                                <div class="logo">
                                    <h1><?php bloginfo('name') ?></h1>
                                </div>
                                <p><?php bloginfo('description') ?></p>
                            </div>
                        </div>
                    </div>
                    <!-- Form Panel    -->
                    <div class="col-12 col-md-6 col-lg-5 bg-white">
                        <div class="form d-flex align-items-center p-4 p-md-5">
                            <?php if ( !get_option('users_can_register') )  { ?>
                            <div class="content">
                                <div class="sign-header h4 mb-2 mb-md-5"><?php _e( '禁止注册', 'i_theme' ); ?></div>
                                <p class="reg-error"><i class="iconfont icon-tishi"></i> <?php echo sprintf( '请联系<a href="mailto:%s">管理员</a>！', get_option( 'admin_email' ) ) ?></p>
                                <div class=" text-muted">
                                    <small><?php _e( '已有账号?', 'i_theme' ); ?> <a href="<?php echo home_url('/login/') ?>" class="signup"><?php _e( '登陆', 'i_theme' ); ?></a></small> 
                                </div>
                            </div>
                            <?php } else { ?>
                            <div class="content">
                                <?php if (!is_user_logged_in()) { ?>
                                <div class="sign-header h4 mb-2 mb-md-5"><?php _e('注册','i_theme') ?></div>
                                <div id="result" class="mb-4 text-danger"></div>
                                <div style="color:#f1404b;height:30px">
                                <?php if(!empty($error)) {
                                    echo '<i class="iconfont icon-crying mr-2"></i>'.$error;
                                }?>
                                </div>
                                <form name="registerform" method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" class="form-validate mb-3" id="wp_login_form">
                                    <div class="form-group mb-0">
                                        <input type="text" name="user_login" tabindex="1" id="user_login" placeholder="用户名" value="<?php if(!empty($sanitized_user_login)) echo $sanitized_user_login; ?>"  size="30" class="input-material"/> 
                                        <div style="color:#f1404b;height:25px"><small><?php if(!empty($user_error))  echo '<i class="iconfont icon-crying mr-2"></i>'.$user_error; ?></small></div>
                                    </div> 
                                    <div class="form-group mb-0">
                                        <input type="text" name="user_email" tabindex="2" id="user_email" placeholder="邮箱" value="<?php if(!empty($user_email)) echo $user_email; ?>"  size="30" class="input-material"/> 
                                        <div style="color:#f1404b;height:25px"><small><?php if(!empty($email_error))  echo '<i class="iconfont icon-crying mr-2"></i>'.$email_error; ?></small></div>
                                    </div> 
                                    <div class="form-group mb-0">
                                        <input type="password" name="user_pass" tabindex="3" id="user_pwd1" placeholder="密码" size="30" class="input-material"/> 
                                        <div style="color:#f1404b;height:25px"><small><?php if(!empty($pass_error))  echo '<i class="iconfont icon-crying mr-2"></i>'.$pass_error; ?></small></div>
                                    </div> 
                                    <div class="form-group mb-0">
                                        <input type="password" name="user_pass2" tabindex="4" id="user_pwd2" placeholder="确认密码" size="30" class="input-material"/> 
                                        <div style="color:#f1404b;height:25px"><small><?php if(!empty($pass_error2))  echo '<i class="iconfont icon-crying mr-2"></i>'.$pass_error2; ?></small></div>
                                    </div> 
                                    <div class="d-flex mt-3">
                                        <input type="hidden" name="user_reg" value="ok" />
                                        <?php  if( LOGIN_007 && io_get_option('io_captcha')['tcaptcha_007'] && io_get_option('io_captcha')['appid_007'] ) { ?>
                                        <input class="btn btn-danger px-4 px-lg-5" type="button" id="TencentCaptcha" value="<?php _e('注册','i_theme') ?>" data-appid="<?php echo io_get_option('io_captcha')['appid_007'] ?>" data-cbfn="loginTicket"/>
                                        <?php } else { ?>
                                        <button id="submit" type="submit" name="submit" class="btn btn-danger px-4 px-lg-5"><?php _e( '注册', 'i_theme' ); ?></button>
                                        <?php } ?>
                                        <a href="<?php echo home_url() ?>" class="btn btn-outline-danger px-4 px-lg-5 ml-auto"><?php _e( '首页', 'i_theme' ); ?></a>
                                    </div> 
                                </form> 
                                <div class=" text-muted">
                                    <small><?php _e( '已有账号?', 'i_theme' ); ?> <a href="<?php echo home_url('/login/') ?>" class="signup"><?php _e( '登陆', 'i_theme' ); ?></a></small> 
                                </div>
                                <div class="login-form mt-4 mb-n4"><?php do_action('login_form', 'resetpass'); ?></div>
                                <?php } else { ?>
                                <div class="sign-header h4 mb-2 mb-md-5"><?php _e( '注册成功', 'i_theme' ); ?></div> 
                                <a href="<?php echo wp_logout_url( home_url() ); ?>" class="btn btn-danger px-4 px-md-5 "><?php _e( '退出登录', 'i_theme' ); ?></a>
                                <?php
                                if (current_user_can('manage_options')) {
                                    echo '&nbsp;&nbsp;<a href="' . admin_url() . '" class="btn btn-outline-danger px-4 px-md-5 ml-auto">' . sprintf(__( '管理站点', 'i_theme' )) . '</a>';
                                } else {
                                    echo '&nbsp;&nbsp;<a href="/user/settings" class="btn btn-outline-danger px-4 px-md-5 ml-auto">' . sprintf(__( '用户中心', 'i_theme' )) . '</a>';
                                }
                                ?>
                                <?php } ?>
                            </div>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="footer-copyright my-4">
            <div class="text-muted text-center">
                <small>Copyright © <a href="<?php echo home_url() ?>" title="<?php bloginfo('name') ?>" rel="home"><?php bloginfo('name') ?></a></small> 
            </div>
        </div>
    </div> 


</body >
</html>
